<?php

namespace App\Http\Resources\Base;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\PaginatedResourceResponse;
use Illuminate\Pagination\LengthAwarePaginator;

class CustomPaginatedResourceResponse extends PaginatedResourceResponse
{
    /**
     * Add the pagination information to the response.
     *
     * @param Request $request
     *
     * @return array
     */
    protected function paginationInformation($request): array
    {
        /** @var LengthAwarePaginator $paginate */
        $paginate = $this->resource->resource;

        return [
            'meta' => [
                'total' => $paginate->total(),
                'limit' => $paginate->perPage(),
                'page' => $paginate->currentPage(),
                'has_more' => $paginate->hasMorePages(),
            ],
        ];
    }
}
